//
//  LFTMCStatusHintView.m
//  Pods
//
//  Created by Thomas Quan on 2017/5/12.
//
//

#import "LFTMCStatusHintView.h"
#import "NTESGlobalMacro.h"
#import "LFTMCUtil.h"

@interface LFTMCStatusHintView()

@property (nonatomic, assign)  LFTMCStatus status;

@end

@implementation LFTMCStatusHintView

- (instancetype)initWithFrame:(CGRect)frame teamMemberInfo:(NIMTeamMember *)teamMemberInfo{
    self = [super initWithFrame:frame];
    if (self) {
        _myTeamInfo = teamMemberInfo;
        self.status = LFTMCStatusNormal;
        self.backgroundColor = [UIColor whiteColor];
        [self setUserInteractionEnabled:YES];
        self.textColor = [UIColor blackColor];
        self.font = [UIFont systemFontOfSize:20];
        self.text = [LFTMCUtil textByStatus:LFTMCStatusNormal];
        self.textColor = UIColorFromRGB(0xCCCCCC);
        self.numberOfLines = 1;
        self.textAlignment = NSTextAlignmentCenter;
        
        [self setSelfHidden:LFTMCStatusNormal];
    }
    return self;
}

- (void)setSelfHidden:(LFTMCStatus) status {
    
    // 需要显示的是， 当前课程已关闭，那么所有人都显示课程已关闭，
    // 或者是课程没关闭,但是处于两种禁言状态，自己又不是管理员，那么就显示出来
    
    if (status == LFTMCStatusCourseEnded) {
        [self setHidden:NO];
        return;
    }
    
    if (status == LFTMCStatusPersonMuted || status == LFTMCStatusTeamMuted) {
        if ([LFTMCUtil isOwnerOrManager:self.myTeamInfo]) {
            return;
        }
        [self setHidden:NO];
        return;
    }
    
    if (status == LFTMCStatusNormal) {
        [self setHidden:YES];
        return;
    }
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

}

- (void)refreshStatus:(LFTMCStatus)status
{
    self.status = status;
    self.text = [LFTMCUtil textByStatus:status];
    [self setSelfHidden:status];
}


- (LFTMCStatus)currentStatus {
    return self.status;
}
@end
